package com.dawan.sbjy.util;

import com.dawan.sbjy.common.RedisPool;
import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;
@Slf4j
public class RedisPoolUtil {
    public  static  String setex(String key,String value,int extime){
        Jedis jedis=null;
        String result=null;
        try{
            jedis= RedisPool.getJedis();
            result=jedis.setex(key,extime,value);
        }catch (Exception e){
            log.error("setex key value extime",key,value);
            RedisPool.returnBrokenResource(jedis);
            return result;
        }
        RedisPool.returnResource(jedis);
        return result;
    }
    public  static  String set(String key,String value){
        Jedis jedis=null;
        String result=null;
        try{
            jedis= RedisPool.getJedis();
            result=jedis.set(key,value);
        }catch (Exception e){
            log.error("set key value",key,value);
            RedisPool.returnBrokenResource(jedis);
            return result;
        }
        RedisPool.returnResource(jedis);
        return result;
    }
    public  static  String get(String key){
        Jedis jedis=null;
        String result=null;
        try{
            jedis= RedisPool.getJedis();
            result=jedis.get(key);
        }catch (Exception e){
            log.error("get value",key);
            RedisPool.returnBrokenResource(jedis);
            return result;
        }
        RedisPool.returnResource(jedis);
        return result;
    }
    public  static  Long expire(String key,int extime){
        Jedis jedis=null;
        Long result=null;
        try{
            jedis= RedisPool.getJedis();
            result=jedis.expire(key,extime);
        }catch (Exception e){
            log.error("get value",key);
            RedisPool.returnBrokenResource(jedis);
            return result;
        }
        RedisPool.returnResource(jedis);
        return result;
    }
    public  static  Long del(String key){
        Jedis jedis=null;
        Long result=null;
        try{
            jedis= RedisPool.getJedis();
            result=jedis.del(key);
        }catch (Exception e){
            log.error("del value",key);
            RedisPool.returnBrokenResource(jedis);
            return result;
        }
        RedisPool.returnResource(jedis);
        return result;
    }
}
